package com.jrx.anytxn.customer.controller;

import com.jrx.anytxn.common.exception.TxnBizException;
import com.jrx.anytxn.customer.dto.customer.CustomerLabelReq;
import com.jrx.anytxn.customer.dto.customer.CustomerLabelRes;
import com.jrx.anytxn.customer.service.ICustomerLabelService;
import com.jrx.anytxn.i18n.response.TxnRespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Api(tags = "客户打标签的api接口")
@RestController
@RequestMapping(value = "/api/customer/customerLabel")
public class CustomerLabelController {

    private static Logger logger = LoggerFactory.getLogger(CustomerLabelController.class);

    @Autowired
    private ICustomerLabelService customerLabelService;

    @ApiOperation(value = "客户打标签API", notes = "客户打标签API")
    @PostMapping("/setCustomerLabel")
    public TxnRespResult<CustomerLabelRes> createCustomerLabel(@Valid @RequestBody CustomerLabelReq req) throws Exception {
        TxnRespResult<CustomerLabelRes> result = new TxnRespResult<>();
        try {
            CustomerLabelRes res=customerLabelService.addCustomerLabel(req);
            result.getSuccess(res);
        } catch (TxnBizException e) {
            logger.error(e.getErrMsg(),e);
            result.getFail(e.getErrCode(), e.getErrMsg());
        }
        return result;
    }



}
